import Cookies from 'js-cookie'
import { getUrlKey } from '@/utils/getUrlKey'

const TokenKey = 'Admin-Token'
const UserInfo = 'Admin-UserInfo'
export function getToken() {
  const tokenid = getUrlKey('tokenid', window.location.href)
  return tokenid
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

export function getUserInfo() {
  if (Cookies.get(UserInfo) === undefined) {
    return
  }
  return Cookies.get(UserInfo) === '' ? '' : JSON.parse(Cookies.get(UserInfo))
}

export function setUserInfo(userInfo) {
  return Cookies.set(UserInfo, userInfo)
}

export function removeUserInfo() {
  return Cookies.remove(UserInfo)
}

